# Maintainer: Mario Emmenlauer <memmenlauer@biodataanalysis.de>

_realname=thrift
pkgbase=mingw-w64-${_realname}-git
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}-git"
pkgver=1.0.0.3db41fa
pkgrel=2
pkgdesc="Apache Thrift is a software framework for scalable cross-language services development (mingw-w64)"
arch=('any')
url='https://thrift.apache.org/'
license=('MIT X11')
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs"
         "${MINGW_PACKAGE_PREFIX}-boost"
         "${MINGW_PACKAGE_PREFIX}-openssl"
         "${MINGW_PACKAGE_PREFIX}-zlib")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-cmake"
             "make"
             "bison"
             "flex"
             "git")
options=('strip')
source=(git+https://github.com/apache/thrift.git#commit=3db41fa
        0001-thrift-build-option-defines.patch)
sha256sums=('SKIP'
            '5819422f02da692faee26837256e27a8d70cd8a3bb6580872bfdc6d56a37527e')

prepare() {
  cd "${srcdir}/${_realname}"

  patch -p1 -i "${srcdir}/0001-thrift-build-option-defines.patch"
}

build() {
  [[ -d "${srcdir}/build-${MINGW_CHOST}" ]] && rm -rf "${srcdir}/build-${MINGW_CHOST}"
  cp -rf "${srcdir}/${_realname}" "${srcdir}/build-${MINGW_CHOST}"
  cd "${srcdir}/build-${MINGW_CHOST}"

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake . \
    -Wno-dev \
    -G"MSYS Makefiles" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DWITH_SHARED_LIB="OFF" \
    -DWITH_STATIC_LIB="ON" \
    -DCMAKE_BUILD_TYPE="Release" \
    -DBUILD_COMPILER="ON" \
    -DBUILD_TESTING="ON" \
    -DBUILD_EXAMPLES="ON" \
    -DBUILD_TUTORIALS="OFF" \
    -DWITH_STDTHREADS="ON" \
    -DWITH_BOOSTTHREADS="OFF" \
    -DWITH_BOOST_STATIC="ON" \
    -DWITH_LIBEVENT="OFF" \
    -DWITH_OPENSSL="ON" \
    -DOPENSSL_USE_STATIC_LIBS="ON" \
    -DWITH_ZLIB="ON" \
    -DWITH_QT4="OFF" \
    -DWITH_QT5="OFF" \
    -DWITH_CPP="ON" \
    -DWITH_C_GLIB="OFF" \
    -DWITH_JAVA="OFF" \
    -DWITH_PYTHON="OFF" \
    -DWITH_HASKELL="OFF"

  make -j1
}

check() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make check
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make DESTDIR="${pkgdir}" -j1 install
  install -Dm644 "${srcdir}/${_realname}/LICENSE" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE.txt"
}
